package transactionimplementation

import (
	"fmt"
	"log"
	"reflect"
	Database "salarypayment-case/DataBase"
	"salarypayment-case/modelimplementation"
	"strconv"
	"time"
)

type TimeCardTransaction struct {
	itsDate  time.Time
	itsHours float64
	itsEmpid int
}

func (tt *TimeCardTransaction) Execute() {
	e := Database.PayrollDatabases.GetEmployee(tt.itsEmpid)

	if e != nil {
		pc := e.GetClassification()

		if reflect.TypeOf(pc) == reflect.TypeOf(modelimplementation.HourlyClassification{}) {
			hc := e.GetClassification().(*modelimplementation.HourlyClassification)
			hc.AddTimeCard(*modelimplementation.CreateTimeCard(tt.itsDate, tt.itsHours))
		} else {
			err := fmt.Errorf(Database.PayrollExceptionMessage.NotHoulyClassification + strconv.Itoa(e.GetEmpid()))
			log.Println(err.Error())
		}
	} else {
		err := fmt.Errorf(Database.PayrollExceptionMessage.EmployeeNotExist + strconv.Itoa(e.GetEmpid()))
		log.Println(err.Error())
	}
}
